package com.ruoyi.performance.service.impl;

import java.math.BigDecimal;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.performance.mapper.ScoreSummaryMapper;
import com.ruoyi.performance.domain.ScoreSummary;
import com.ruoyi.performance.service.IScoreSummaryService;

/**
 * 分数汇总Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-24
 */
@Service
public class ScoreSummaryServiceImpl implements IScoreSummaryService 
{
    @Autowired
    private ScoreSummaryMapper scoreSummaryMapper;

    /**
     * 查询分数汇总
     * 
     * @param id 分数汇总主键
     * @return 分数汇总
     */
    @Override
    public ScoreSummary selectScoreSummaryById(Long id)
    {
        return scoreSummaryMapper.selectScoreSummaryById(id);
    }

    /**
     * 查询分数汇总列表
     * 
     * @param scoreSummary 分数汇总
     * @return 分数汇总
     */
    @Override
    public List<ScoreSummary> selectScoreSummaryList(ScoreSummary scoreSummary)
    {
        return scoreSummaryMapper.selectScoreSummaryList(scoreSummary);
    }

    /**
     * 新增分数汇总
     * 
     * @param scoreSummary 分数汇总
     * @return 结果
     */
    @Override
    public int insertScoreSummary(ScoreSummary scoreSummary)
    {
        return scoreSummaryMapper.insertScoreSummary(scoreSummary);
    }

    /**
     * 修改分数汇总
     * 
     * @param scoreSummary 分数汇总
     * @return 结果
     */
    @Override
    public int updateScoreSummary(ScoreSummary scoreSummary)
    {
        return scoreSummaryMapper.updateScoreSummary(scoreSummary);
    }

    /**
     * 批量删除分数汇总
     * 
     * @param ids 需要删除的分数汇总主键
     * @return 结果
     */
    @Override
    public int deleteScoreSummaryByIds(Long[] ids)
    {
        return scoreSummaryMapper.deleteScoreSummaryByIds(ids);
    }

    /**
     * 删除分数汇总信息
     * 
     * @param id 分数汇总主键
     * @return 结果
     */
    @Override
    public int deleteScoreSummaryById(Long id)
    {
        return scoreSummaryMapper.deleteScoreSummaryById(id);
    }

    @Override
    public void updatesm(ScoreSummary scoreSummary) {
        Long id = scoreSummary.getId();
        ScoreSummary scoreSummary1 = scoreSummaryMapper.selectScoreSummaryById(id);
        BeanUtil.copyProperties(scoreSummary,scoreSummary1);
        Integer bonusPoints = scoreSummary1.getBonusPoints();
        Integer minusPoints = scoreSummary1.getMinusPoints();
        Integer selfscore = scoreSummary1.getSelfscore();
        BigDecimal add = new BigDecimal(bonusPoints);
        BigDecimal sub = new BigDecimal(minusPoints);
        BigDecimal total = new BigDecimal(selfscore);
        BigDecimal subtract = total.add(add).subtract(sub);
        Integer i = subtract.intValue();
        scoreSummary1.setSelfscore(i);
        scoreSummaryMapper.updateScoreSummary(scoreSummary1);
    }
}
